package com.bst.web.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bst.common.exception.base.BaseException;
import com.bst.md.domain.MdMedTbFld;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bst.common.annotation.Log;
import com.bst.common.enums.BusinessType;
import com.bst.md.domain.MdMedDim;
import com.bst.md.service.IMdMedDimService;
import com.bst.common.core.controller.BaseController;
import com.bst.common.core.domain.AjaxResult;
import com.bst.common.utils.poi.ExcelUtil;
import com.bst.common.core.page.TableDataInfo;

/**
 * 维度管理Controller
 * 
 * @author ruoyi
 * @date 2024-03-07
 */
@Controller
@RequestMapping("/base/md/dim")
public class MdMedDimController extends BaseController
{
    private String prefix = "base/base/md/dim";

    @Autowired
    private IMdMedDimService mdMedDimService;

    @GetMapping()
    public String dim()
    {
        return prefix + "/dim";
    }

    /**
     * 查询维度管理列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MdMedDim mdMedDim)
    {
        startPage();
        List<MdMedDim> list = mdMedDimService.selectMdMedDimList(mdMedDim);
        return getDataTable(list);
    }

    /**
     * 导出维度管理列表
     */
    @Log(title = "维度管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MdMedDim mdMedDim)
    {
        List<MdMedDim> list = mdMedDimService.selectMdMedDimList(mdMedDim);
        ExcelUtil<MdMedDim> util = new ExcelUtil<MdMedDim>(MdMedDim.class);
        return util.exportExcel(list, "维度管理数据");
    }

    /**
     * 新增维度管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存维度管理
     */
    @Log(title = "维度管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MdMedDim mdMedDim)
    {
        return toAjax(mdMedDimService.insertMdMedDim(mdMedDim));
    }

    /**
     * 修改维度管理
     */
    @GetMapping("/edit/{idDim}")
    public String edit(@PathVariable("idDim") Long idDim, ModelMap mmap)
    {
        MdMedDim mdMedDim = mdMedDimService.selectMdMedDimByIdDim(idDim);
        mmap.put("mdMedDim", mdMedDim);
        return prefix + "/edit";
    }

    /**
     * 修改保存维度管理
     */
    @Log(title = "维度管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MdMedDim mdMedDim)
    {
        return toAjax(mdMedDimService.updateMdMedDim(mdMedDim));
    }

    /**
     * 删除维度管理
     */
    @Log(title = "维度管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mdMedDimService.deleteMdMedDimByIdDims(ids));
    }

    @ApiOperation(value = "查询维度数据")
    @GetMapping(value = "/findDimData")
    @ResponseBody
    public TableDataInfo findDimData(String tableName,String search) throws BaseException {
        AjaxResult result = mdMedDimService.findDimDataByTableName(tableName);
        List<Map<String,Object>> list=null;
        if(AjaxResult.isSuccess(result)) {
            list = (List<Map<String,Object>>)result.get(AjaxResult.DATA_TAG);
        }
        return getDataTable(list);
    }


}
